﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBService;
using DBService.Admin;

public partial class administration_Default2 : System.Web.UI.Page
{
    CompanyManager service = null;
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected string GetImageDir()
    {
        return "";//Master.Root + "/upload/";
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {

        if (!gridBind())
        {
            lblCompNotFound.Visible = true;
            gvCompanies.Visible = false;
        }
    }

    private bool gridBind()
    {
        service = new DBService.Admin.CompanyManager();
        var items = service.GetDeletedCompanies(txtCompanySearchName.Value);
        if (items.Count <= 0)
        {
            return false;
        }
        lblCompNotFound.Visible = false;
        gvCompanies.Visible = true;
        gvCompanies.DataSource = items;
        gvCompanies.DataBind();
        return true;
    }

    protected void ReviewGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("RestoreCommand"))
        {
            service = new CompanyManager();
            int row = Int32.Parse(e.CommandArgument.ToString());
            var compID = int.Parse(gvCompanies.Rows[row].Cells[0].Text.ToString());
            service.RestoreCompany(compID);
            gridBind();
        }
    }
}